package com.hollycrm.hollysqm.handle.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;

import com.hollycrm.hollysqm.entities.TblQmPlan;

/**
 * 质检单过滤，同一评分模板下已抽取的质检单不在重复抽取
 * @author jianglong
 * @date 2017年5月8日 下午2:54:21
 */
@Service
public class PaperFilterService {

	@Autowired
    private JdbcTemplate jdbc;
	
	/**
	 * 过滤数据质检单数据
	 * @param paln
	 */
	public void filter(TblQmPlan plan){
		String sql = "delete from tbl_qm_plan_extract where plan_id=? and data_id in (";
		sql += "select paper_detail_id from tbl_qm_paper where standard_id=? and paper_type=?)";
		jdbc.update(sql, new Object[]{plan.getPlanId(),plan.getStandardId(),plan.getDataType()});
	}
	
	/**
	 * 过滤指定坐席重复抽取的数据质检单
	 * @param plan
	 * @param agentCode
	 * @return
	 */
	public int filterUser(TblQmPlan plan,String agentCode){
		String sql = "delete from tbl_qm_plan_extract where plan_id=? and data_id in (";
		sql += "select paper_detail_id from tbl_qm_paper where standard_id=? and paper_type=? and agent_code=?)";
		return jdbc.update(sql, new Object[]{plan.getPlanId(),plan.getStandardId(),plan.getDataType(),agentCode});
	}
}
